<?php
    require_once("../api.php");
    session_start();
	$phone = $_POST['phone'];
	$password = $_POST['password'];
	
	$db = new SQLite3('../chatroom.db');//连接数据库
	$sql = "select * from user where phone = '$phone'";
	//输出查询结果
	$result = $db->query($sql);
	if( $row = $result -> fetchArray(SQLITE3_ASSOC) ){
		if( $row["password"] == $password ){
			//设置登陆位
			$sql = "update user set online = 1 where phone = '$phone'";
			$db->exec($sql);
            $_SESSION['user'] = array(
                'user_id' => $row['user_id'],
                'nickName' => $row['nickname'],
                'iconPath' => $row['icon_path'],
                'sex' => $row['sex']
            );
			ajaxJSON( true, "success",$row['user_id']);
		} else{
			ajaxJSON( false, "password_error" );
		}
	} else{
		ajaxJSON( false, "user_not_exist" );
	}
		
	